//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    imgUrls: [
      app.globalData.serverUrl + "uploads/wxxcx/banner.jpg"
    ],
    first: app.globalData.serverUrl +"uploads/wxxcx/11.png",
    second: app.globalData.serverUrl + "uploads/wxxcx/12.png",
    third: app.globalData.serverUrl + "uploads/wxxcx/13.png",
    forth: app.globalData.serverUrl + "uploads/wxxcx/14.png",
    fifth: app.globalData.serverUrl + "uploads/wxxcx/15.png",
    sixth: app.globalData.serverUrl + "uploads/wxxcx/16.png",
    seventh: app.globalData.serverUrl + "uploads/wxxcx/17.png",
    eighth: app.globalData.serverUrl + "uploads/wxxcx/18.png",
    current: 0,  //默认值为0
    indicatorDots: false,
    vertical: true,
    autoplay: true,
    circular: true,
    interval: 6000,
    duration: 500,
    previousMargin: 0,
    nextMargin: 0,
    topNavH: '65px',
    topimgH: '200px',
    swiperW: '338px',
    swiperH: '150px',
    swiperT: '189px',
    marginTop: '80px'
  },
  
  onReady: function (e) {
    
  },
  onLaunch: function(){
    const updateManager = wx.getUpdateManager()

    updateManager.onCheckForUpdate(function (res) {
      // 请求完新版本信息的回调
      console.log(res.hasUpdate)
    })

    updateManager.onUpdateReady(function () {
      wx.showModal({
        title: '更新提示',
        content: '新版本已经准备好，是否重启小程序？',
        success: function (res) {
          if (res.confirm) {
            // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
            updateManager.applyUpdate()
          }
        }
      })
    })

    updateManager.onUpdateFailed(function () {
      // 新版本下载失败
      wx.showModal({
        title: '提示',
        content: '检查到有新版本，但下载失败，请稍后尝试',
        showCancel: false,
      })
      
    })
  },
  onLoad: function(){
    var that = this
    wx.getSystemInfo({
      success: res => {
        var windowHeight = res.windowHeight;
        var windowWidth = res.windowWidth;
        var statusBarHeight = res.statusBarHeight;
        // console.log('statusBarHeight:' + statusBarHeight)
        var topNavH = (statusBarHeight + 45);
        var topimgH = (windowWidth / 414 * 200);
        var swiperH = (windowWidth / 360 * 338 * 150 / 338);
        that.setData({
          picHeight: (windowHeight / 640 * 240) + 'px',
          picWidth: (windowWidth / 360 * 170) + 'px',
          topNavH: topNavH + 'px',
          topimgH: topimgH + 'px',
          swiperW: (windowWidth / 360 * 338) + 'px',
          swiperH: swiperH + 'px',
          
          marginTop: swiperH * 0.55 + 'px'   //(windowHeight / 732 * 81) + 'px',
        })
        if(windowHeight<800){
          if (windowHeight == 741) {
            that.setData({
              swiperT: (windowHeight / 732 * 175) + 'px'
              // swiperT: topNavH + topimgH * 0.65 + 'px'
            })
          }else{
            that.setData({
              // swiperT: (windowHeight / 732 * 195) + 'px'
              swiperT: topNavH + topimgH * 0.65 + 'px'
            })
          }
          
          
        }else{
          that.setData({
            swiperT: (windowHeight / 812 * 180) + 'px'
          })
        }
      }
    })
    wx.request({
      url: app.globalData.apiUrl + 'api/scansence/getBanners',
      method: 'GET',
      data: {
        
      },
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        // console.log(res.data)
        if(res.data){
          that.setData({
            imgUrls: res.data
          })
        }
        
        
      },
      fail: function () {
        
      },
      complete: function () {
      }
    })
  },
  getCurrent: function (e) {
    var cur = e.detail.current;    //有兴趣的小伙伴可以打印e,瞅瞅它长啥样
    console.log("cur"+cur)
    this.setData({
      current: cur
    });
  },
  getIndex: function (e) {
    var id = this.data.current;   //+1是为了让打印结果好读一点
    console.log(id)
    if(id==0){
      wx.navigateTo({
        url: '/pages/news/seventh',
      })
    } else if (id == 1) {
      wx.navigateTo({
        url: '/pages/news/seventh1',
      })
    } else if (id == 2) {
      wx.navigateTo({
        url: '/pages/news/seventh2',
      })
    } else if (id == 3) {
      wx.navigateTo({
        url: '/pages/news/seventh3',
      })
    } else if (id == 4) {
      wx.navigateTo({
        url: '/pages/news/seventh4',
      })
    } else if (id == 5) {
      wx.navigateTo({
        url: '/pages/news/seventh5',
      })
    }
  },
  onShow:function(){
    if(typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0
      })
    }
  },
  getnews: function(){
    wx.navigateTo({
      url: '/pages/news/xuting',
    })
  },
  first: function () {
    wx.navigateTo({
      url: '/pages/news/first',
    })
  },
  second: function () {
    wx.navigateTo({
      url: '/pages/news/second',
    })
  },
  third: function () {
    wx.navigateTo({
      url: '/pages/news/third',
    })
  },
  forth: function () {
    wx.navigateTo({
      url: '/pages/news/forth',
    })
  },
  fifth: function () {
    wx.navigateTo({
      url: '/pages/news/fifth',
    })
  },
  sixth: function () {
    wx.navigateTo({
      url: '/pages/news/sixth',
    })
  },
  seventh: function (param) {
    console.log(param)
    wx.navigateTo({
      url: '/pages/news/seventh',
    })
  },
   /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    let users = wx.getStorageSync('userInfo');
    // if (res.from === 'button') { }
    return {
      title: '青岛成就展',
      path: '/pages/index/index',
      success: function (res) {
        wx.showToast({
          title: '已转发',
          icon: 'success',
          duration: 2000
        })
      }
    }

  }
})
